﻿<?php
    class sscls_ProductModel extends sscls_Model
    {   

        function __construct()
        {
            parent::__construct();
        }
       function getAttries()
	   {
			$query='select u.name as username,
							p.*,c.name as catname
						from product_attri as p
						left join users as u on p.created_by=u.id
						left join categories as c on c.id=p.catid';
			return $this->_db->loadObjectList($query);
	   }
	   function getAttriItem($id)
	   {
			return $this->_db->loadObject('select * from product_attri where id='.(int)$id);
	   }
	   
		function getCategories()
		
		{
			$query='select * from categories';
			return $this->_db->loadObjectList($query);
			
		}
	   function getProducts($catid)
	   {
			$query='select p.*, (select count(id) from product_images where productid=p.id) as totalimage, (select name from categories where id=p.mode) as mode from products as p 
				left join categories as c on c.id=p.catid
				where p.catid='.$catid;
			return $this->_db->loadObjectList($query);
	   }
	   
	  
	   function getAttri($catid)
	   {
		$query='select * from product_attri where catid='.$catid.' order by id';
		return $this->_db->loadObjectList($query);
		
	   }
	   
	    function getAttriValue($attri,$productid)
	   {
			$query='select * from product_attri_value where idattri ='.$attri.' and product_id='.$productid.' order by idattri ';
			$row= $this->_db->loadObject($query);
			return isset($row->value)?$row->value:'';
		
	   }
	   
	   function store1($data,$tablename)
	   {
			$result=$this->store($data,$tablename);
			return $result;
	   }
	   
	   function getItem($id)
	   {
			return $this->_db->loadObject('select * from products where id='.$id);
	   }
	   
	   function removeattri($ids)
	   {
			$sql='delete from product_attri where id in ('.$ids.')';
		return $this->_db->query($sql);
	   }
	   
	    function removeproduct($ids)
	   {
			$sql='delete from products where id in ('.$ids.')';
		return $this->_db->query($sql);
	   }
	   
	   function removeAttriByProductId($productid)
	   {
			$sql='delete from product_attri_value where product_id ='.(int)$productid;
			return $this->_db->query($sql);
	   }
	   function getID()
		{
			return $this->_db->insert_id();
		}
		function getImages($productid)
		{
			return $this->_db->loadObjectList('select * from product_images where productid='.(int)$productid);
		}
		
		function getImage($idimage)
		{
			return $this->_db->loadObject('select * from product_images where id='.(int)$idimage);
		}
		 
		 function removeImage($ids)
	   {
		if(is_array($ids))
			$sql='delete from product_images where id in ('.implode(',',$ids).')';
		else
			$sql='delete from product_images where id ='.(int)$ids;
		return $this->_db->query($sql);
	   }
	   
	   function getKindMoto()
		{
			$query='select * from categories where parentid=11';
			return $this->_db->loadObjectList($query);
			
		}
		
		function getModel($id)
		{
			$query='select * from categories where parentid='.$id;
			return $this->_db->loadObjectList($query);
			
		}
		
	   
	  
    }
?>
